<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="util.*"%>
<%@page import="dal.*"%>
<%@ page import="model.*,java.util.*"%>
<%
	GenericDal<DocumentModel, DocumentModelExt> dal = new GenericDal<DocumentModel, DocumentModelExt>(
			new DocumentModel());
	DocumentModelExt queryCount = new DocumentModelExt();
	int count = dal.count(queryCount);

	int pageIndex = 1;
	if (request.getParameter("pageIndex") != null
			&& !request.getParameter("pageIndex").isEmpty()) {
		try {
			pageIndex = Integer.parseInt(request
					.getParameter("pageIndex"));
		} catch (Exception e) {
		}
	}

	int pageSize = 20;
	if (request.getParameter("pageSize") != null
			&& !request.getParameter("pageSize").isEmpty()) {
		try {
			pageSize = Integer.parseInt(request
					.getParameter("pageSize"));
		} catch (Exception e) {
		}
	}

	int noOfPage = count / pageSize;
	if (count % pageSize > 0) {
		noOfPage++;
	}

	DocumentModelExt query = new DocumentModelExt();
	query.setLimit(pageSize);
	query.setOffset((pageIndex - 1) * pageSize);
	List<DocumentModel> list = dal.selectList(query);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Document List</title>
</head>
<body>
	<jsp:include page="menu.jsp"></jsp:include>
	<table class="tblPaging">
		<tr class="trPaging">
			<td class="tdPaging">
				<%
					for (int i = 1; i <= noOfPage; i++) {
						if (i == pageIndex) {
				%> <span class="lblPaging"><%=i%></span> <%
 	} else {
 %> <a class="hrefPaging"
				href="documentList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
				<%
					}
					}
				%>
			</td>
		</tr>
	</table>
	<table class="tblList">
		<tr class="tblListHeader">
			<td class="tdListHeader"></td>
			<td class="tdListHeader"></td>
			<td class="tdListHeader">Id</td>
			<td class="tdListHeader">Name</td>
			<td class="tdListHeader">Code</td>
			<td class="tdListHeader">Description</td>
			<td class="tdListHeader">Is Template</td>
			<td class="tdListHeader">Object Type</td>
			<td class="tdListHeader">Object Id</td>
			<td class="tdListHeader">Need Approval</td>
			<td class="tdListHeader">Status</td>
			<td class="tdListHeader">Is Draft</td>
			<td class="tdListHeader">Notification</td>
			<td class="tdListHeader">Created</td>
			<td class="tdListHeader">Creator</td>
			<td class="tdListHeader">Updated</td>
			<td class="tdListHeader">Updator</td>
			<td class="tdListHeader">Deleted</td>
			<td class="tdListHeader">Deletion Time</td>

		</tr>

		<%
			int size = list.size();
			for (int i = 0; i < size; i++) {
				DocumentModel obj = list.get(i);
		%>

		<tr class="trListItem">
			<td class="tdListInt"><%=i + 1%></td>
			<td class="tdListHref"><a
				href="document?mode=edit&id=<%=obj.getId()%>
">Edit</a>
			</td>

			<td class="tdList"><%=obj.getId()%></td>
			<td class="tdListText"><%=obj.getName()%></td>
			<td class="tdListText"><%=obj.getCode()%></td>
			<td class="tdListTextarea"><%=obj.getDescription()%></td>
			<td class="tdListBool"><%=obj.getIsTemplate()%></td>
			<td class="tdListText"><%=obj.getObjectType()%></td>
			<td class="tdListInt"><%=obj.getObjectId()%></td>
			<td class="tdListBool"><%=obj.getNeedApproval()%></td>
			<td class="tdListInt"><%=obj.getStatus()%></td>
			<td class="tdListBool"><%=obj.getIsDraft()%></td>
			<td class="tdListInt"><%=obj.getNotification()%></td>
			<td class="tdListDateTime"><%=obj.getCreated()%></td>
			<td class="tdListInt"><%=obj.getCreator()%></td>
			<td class="tdListDateTime"><%=obj.getUpdated()%></td>
			<td class="tdListInt"><%=obj.getUpdator()%></td>
			<td class="tdListBool"><%=obj.getDeleted()%></td>
			<td class="tdListDateTime"><%=obj.getDeletionTime()%></td>

		</tr>
		<%
			}
		%>
	</table>
</body>
</html>